package com.tsj.spzx.user.controller;

import com.tsj.spzx.model.entity.base.Region;
import com.tsj.spzx.model.vo.common.Result;
import com.tsj.spzx.model.vo.common.ResultCodeEnum;
import com.tsj.spzx.user.service.AddressRegionService;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api/user/region")
@Tag(name = "行政区域接口")
public class AddressRegionController {

    @Autowired
    private AddressRegionService addressRegionService;

    /**
     * 根据parentCode查询地区(即parentCode=0 查询所有的省级) 一层一层的查
     * @param parentCode
     * @return
     */
    @GetMapping("/findByParentCode/{parentCode}")
    public Result<List<Region>> findByParentCode(@PathVariable("parentCode") String parentCode) {
        List<Region> regionList = addressRegionService.findByParentCode(parentCode);
        return Result.build(regionList, ResultCodeEnum.SUCCESS);
    }

}
